<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Konten_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		
	}

	function getKonten($page=FALSE,$query=FALSE,$id=FALSE,$limit=FALSE,$offset=FALSE)
	{
		if($page == 'hal'):
			if (!$query):
				$this->db->where('konten_id',$id);
				return $this->db->get('tb_konten')->row();
			elseif($query=='all'):
				$query = $this->db->query("SELECT * FROM tb_konten WHERE page != 'ticker'");
				return $query->result_array();
			endif;
		elseif($page == 'berita'):	
			if (!$query):
				$this->db->where('konten_id',$id);
				return $this->db->get('tb_konten')->row();
			elseif($query=='all'):
				$this->db->limit($limit,$offset);
				$this->db->where('page','ticker');
				$this->db->order_by('konten_id','desc');
				return $this->db->get('tb_konten')->result_array();
			elseif($query=='all_front'):
				$this->db->limit($limit,$offset);
				$this->db->where('page','ticker');
				$this->db->where('published','y');
				$this->db->order_by('konten_id','desc');
				return $this->db->get('tb_konten')->result_array();
			endif;
		elseif($page == 'profile'):	
			$this->db->where('page','profile');
			$this->db->limit(1);
			return $this->db->get('tb_konten')->row();
		elseif($page == 'ticker'):	
			$this->db->where('page','ticker');
			$this->db->order_by('konten_id','desc');
			$this->db->limit(10);
			return $this->db->get('tb_konten')->result_array();
		elseif($page == 'faq'):	
			$this->db->where('page','faq');
			$this->db->limit(1);
			return $this->db->get('tb_konten')->row();
			
		endif;
	}

	function addKonten($data)
	{
		$this->db->insert('tb_konten',$data);
	}

	function editKonten($id,$data)
	{
		$this->db->where('konten_id',$id);
		$this->db->update('tb_konten',$data);
	}

	function deleteKonten($id)
	{
		$this->db->where('konten_id', $id);
		$this->db->delete('tb_konten');
	}

}
